package com.ruoyi.msg.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.msg.mapper.ChatMsgMapper;
import com.ruoyi.msg.domain.ChatMsg;
import com.ruoyi.msg.service.IChatMsgService;

/**
 * 聊天消息Service业务层处理
 * 
 * @author zzzyh
 * @date 2025-10-12
 */
@Service
public class ChatMsgServiceImpl implements IChatMsgService 
{
    @Autowired
    private ChatMsgMapper chatMsgMapper;

    /**
     * 查询聊天消息
     * 
     * @param id 聊天消息主键
     * @return 聊天消息
     */
    @Override
    public ChatMsg selectChatMsgById(Long id)
    {
        return chatMsgMapper.selectChatMsgById(id);
    }

    /**
     * 查询聊天消息列表
     * 
     * @param chatMsg 聊天消息
     * @return 聊天消息
     */
    @Override
    public List<ChatMsg> selectChatMsgList(ChatMsg chatMsg)
    {
        return chatMsgMapper.selectChatMsgList(chatMsg);
    }

    /**
     * 新增聊天消息
     * 
     * @param chatMsg 聊天消息
     * @return 结果
     */
    @Override
    public int insertChatMsg(ChatMsg chatMsg)
    {
        chatMsg.setCreateTime(DateUtils.getNowDate());
        return chatMsgMapper.insertChatMsg(chatMsg);
    }

    /**
     * 修改聊天消息
     * 
     * @param chatMsg 聊天消息
     * @return 结果
     */
    @Override
    public int updateChatMsg(ChatMsg chatMsg)
    {
        return chatMsgMapper.updateChatMsg(chatMsg);
    }

    /**
     * 批量删除聊天消息
     * 
     * @param ids 需要删除的聊天消息主键
     * @return 结果
     */
    @Override
    public int deleteChatMsgByIds(Long[] ids)
    {
        return chatMsgMapper.deleteChatMsgByIds(ids);
    }

    /**
     * 删除聊天消息信息
     * 
     * @param id 聊天消息主键
     * @return 结果
     */
    @Override
    public int deleteChatMsgById(Long id)
    {
        return chatMsgMapper.deleteChatMsgById(id);
    }

    @Override
    public String selectRoomNameById(Long roomId) {
        return chatMsgMapper.selectRoomNameById(roomId);
    }

    @Override
    public String selectUserNameById(Long senderId) {
        return chatMsgMapper.selectUserNameById(senderId);
    }

    @Override
    public Long getIdByUserName(String userName) {
        return chatMsgMapper.getIdByUserName(userName);
    }
}
